package ca.usherbrooke.domus.sipnmove2.controller.phone;

import javax.swing.SwingUtilities;

import ca.usherbrooke.domus.sipnmove2.model.call.Call;
import ca.usherbrooke.domus.sipnmove2.model.phone.NewCallListener;
import ca.usherbrooke.domus.sipnmove2.view.call.CallView;
import ca.usherbrooke.domus.sipnmove2.view.call.CallViewFactory;

/**
 * Process a new call event by displaying the associated call view
 */
public class NewCallViewController implements NewCallListener {

	/**
	 * Call view factory
	 */
	private CallViewFactory callViewFactory;

	@Override
	public void processNewCall(Call call) {
		
		// Clone the prototype view
		final CallView callView = callViewFactory.createCallView(call);
		call.addCallObserver(callView);

		// Invoke display in Swing thread
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				callView.display();
			}
		});
		
	}

	/**
	 * @param callViewFactory the callViewFactory to set
	 */
	public void setCallViewFactory(CallViewFactory callViewFactory) {
		this.callViewFactory = callViewFactory;
	}

}
